<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type='text/javascript' src='../js/vue.js'></script>

</head>

<body>
    <div id="root">

        <!-- 
            v-for指令
                用于展示列表数据
                v-for='(item,index) in xxx' :key='yyy'
                可遍历：数组、对象、字符串（少）、指定次数（少）
        -->

        <!-- 遍历数组 -->
        <h2>成员列表</h2>
        <ul>
            <!-- 在v-for中只能接受两个值，第一个值是对象，第二个是索引 -->
            <li v-for='(person,index) in persons' :key='index'>
                {{index}}--{{person.name}}-{{person.age}}
            </li>
        </ul>

        <!-- 遍历对象 -->
        <h2>歌曲信息</h2>
        <ul>
            <li v-for='(value,index) in song' :key='index'>
                {{index}}--{{value}}
            </li>
        </ul>

        <!-- 遍历字符串 -->
        <h2>测试遍历字符串</h2>
        <ul>
            <li v-for='(char,index) in str' :key='index'>
                {{index}}--{{char}}
            </li>
        </ul>

        <!-- 遍历指定次数 -->
        <h2>测试遍历指定次数</h2>
        <ul>
            <li v-for='(number,index) of 5' :key='index'>
                {{index}}--{{number}}
            </li>
        </ul>

    </div>
    <script>
        Vue.config.productionTip = false;

        const vm = new Vue({
            el: '#root',
            data: {
                persons: [
                    { id: '001', name: 'SONG', age: 18 },
                    { id: '002', name: 'LIU', age: 16 },
                    { id: '003', name: 'MA', age: 19 },
                ],
                song: {
                    name: 'LHC',
                    singer: 'SONG',
                    color: 'blue'
                },
                str:'SONGYAXUAN'
            }
        })

    </script>
</body>

</html>